package day;

public class P673 {

    public int findNumberOfLIS(int[] nums) {
        int len = nums.length;
        if (len < 2) {
            return len;
        }

        int[] dp = new int[nums.length];
        dp[0] = 1;
        int maxLen = 1;
        int idx = 0;
        for (int i = 1; i < len; i++) {
            int max = 1;
            for (int j = i - 1; j >= 0; j--) {
                if (nums[j] < nums[i]) {
                    max = Math.max(max, dp[j] + 1);
                }
            }
            dp[i] = max;
            if (maxLen < dp[i]) {
                maxLen = dp[i];
                idx = i;
            }
        }
        return findCount(nums, dp, Integer.MIN_VALUE, 1, 0, maxLen);
    }

    /**
     * @param nums
     * @param dp
     * @param len    寻找当前len
     * @param idx    从当前位置开始
     * @param maxLen 最大长度
     * @return
     */
    private int findCount(int[] nums, int[] dp, int now, int len, int idx, int maxLen) {
        if (len > maxLen) {
            return 1;
        } else {
            int total = 0;
            for (int i = idx; i < nums.length; i++) {
                if (dp[i] == len && nums[i] > now) {
                    total += findCount(nums, dp, nums[i], len + 1, i + 1, maxLen);
                }
            }
            return total;
        }
    }

    public static void main(String[] args) {
        int count = new P673().findNumberOfLIS(new int[]{
               // 1, 2, 4, 3, 5, 4, 7, 2
                2,2,2,2,2
        });
        System.out.println(count);
    }
}
